package no.evalanche.fragments;


import no.evalanche.io.EntityList;
import no.evalanche.io.ResultsGraphicsIO;
import no.evalanche.io.ServiceList;
import no.evalanche.main.R;
import no.evalanche.statsgraph.ResultsGraphics;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

/**
 * 
 * @author vholms
 *
 * Presents this users history of MC exercises
 *
 *
 */
public class MyProgress extends SessionFragment {

	private RelativeLayout theLayout;
	
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		theLayout = (RelativeLayout) getView();
	}
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {		
		// Next line picks the layout for this fragment
		return inflater.inflate(R.layout.mcresults, container, false);
	}
	
	@Override
	public void execute() {
		status(getText(R.string.mc_stapleheader).toString());			
		ResultsGraphicsIO t = new ResultsGraphicsIO(sessionId, averageResponseGraph);
		EntityList pams = new EntityList(1);
		pams.add(new BasicNameValuePair("request", ServiceList.RESULTS.toString()));
		t.execute(pams);
	}


	private Handler averageResponseGraph = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			JSONObject jso = (JSONObject) msg.obj;
			ResultsGraphics test = new ResultsGraphics(getActivity(), jso); 
			theLayout.addView(test);
		}
	};

}